
import { render } from "@testing-library/react";
import React from "react";
// 
const mag = '你好'
const arr=['李森','刘备']
const styleBg ={
    background:'#f00'
}
// 视图更新需要用setState
export default class App extends React.Component{
   constructor(props){
       super(props)
       this.state={
        num:1
    }
   }
    render(){
        return (
            <div>
                <h1 style={styleBg}>123123{mag}
                    
                </h1>
                <h2>数字为：{this.state.num}</h2>
                <button onClick={this.addNum.bind(this)}>加</button>
                <button onClick={()=>this.addNum()}>箭头函数加</button>
                <ul>
                    {
                        arr.map((item,index)=>{
                            return <li key={index}>{item}</li>
                        })
                    }      
                </ul>
            </div>
           
        )
    }
    addNum(){
       console.log(this);
       this.setState({
           num:this.state.num+1
       })
    }
}
